package com.petRescueCenter.demo.posting.entity.dto;

import java.util.Date;
import java.util.Set;

import javax.persistence.Temporal;
import javax.persistence.TemporalType;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.petRescueCenter.demo.common.enumPackage.LockedEmun;
import com.petRescueCenter.demo.common.enumPackage.pTypeEmun;
import com.petRescueCenter.demo.img.entity.Img;
import com.petRescueCenter.demo.posting.entity.Posting;

import io.swagger.annotations.ApiModelProperty;

public class PostingDTO {
	@ApiModelProperty(name = "id", value = "帖子id", required = false)
	private Long id;
	@ApiModelProperty(name = "imgs", value = "视频或者图片", required = false)
	private Set<Img> imgs;
	@ApiModelProperty(name = "createTime", value = "创建时间", required = false)
	private Date createTime;
	@ApiModelProperty(name = "title", value = "题目", required = false)
	private String title;
	@ApiModelProperty(name = "authorName", value = "作者名称", required = false)
	private String authorName;
	@ApiModelProperty(name = "content", value = "内容", required = false)
	private String content;
	@ApiModelProperty(name = "type", value = "类型", required = false)
	private String type;
	// 保存还是发布
	private LockedEmun state;
	private LockedEmun attention;

	public Long getId() {
		return id;
	}

	public LockedEmun getAttention() {
		return attention;
	}

	public void setAttention(LockedEmun attention) {
		this.attention = attention;
	}

	public Set<Img> getImgs() {
		return imgs;
	}

	@Temporal(TemporalType.TIMESTAMP)
	@JsonFormat(pattern = "yyyy/MM/dd HH:mm:ss", timezone = "GMT+8")
	public Date getCreateTime() {
		return createTime;
	}

	public LockedEmun getState() {
		return state;
	}

	public void setState(LockedEmun state) {
		this.state = state;
	}

	public String getTitle() {
		return title;
	}

	public String getAuthorName() {
		return authorName;
	}

	public String getType() {
		return type;
	}

	public String getContent() {
		return content;
	}

	public void setContent(String content) {
		this.content = content;
	}

	public void setType(String type) {
		this.type = type;
	}

	public void setAuthorName(String authorName) {
		this.authorName = authorName;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public void setImgs(Set<Img> imgs) {
		this.imgs = imgs;
	}

	@Temporal(TemporalType.TIMESTAMP)
	@JsonFormat(pattern = "yyyy/MM/dd HH:mm:ss", timezone = "GMT+8")
	public void setCreateTime(Date createTime) {
		this.createTime = createTime;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public static PostingDTO entityToDto(Posting entity, PostingDTO dto) {
		dto.setAuthorName(entity.getAuthor().getName());
		dto.setCreateTime(entity.getCreateTime());
		dto.setId(entity.getId());
		dto.setImgs(entity.getImgs());
		dto.setTitle(entity.getTitle());
		dto.setContent(entity.getContent());
		dto.setType(entity.getType().getName());
		dto.setState(entity.getState());
		return dto;
	}

	public static Posting dtoToEntity(Posting entity, PostingDTO dto) {
		entity.setContent(dto.getContent());
		entity.setCreateTime(dto.getCreateTime());
		entity.setId(dto.getId());
		entity.setImgs(dto.getImgs());
		entity.setTitle(dto.getTitle());
		if (dto.getType().equals("文章")) {
			entity.setType(pTypeEmun.POSTING);
		} else if (dto.getType().equals("失宠招领")) {
			entity.setType(pTypeEmun.FINDO);
		} else if (dto.getType().equals("寻宠启示")) {
			entity.setType(pTypeEmun.FINDP);
		} else if (dto.getType().equals("注意事项")) {
			entity.setType(pTypeEmun.WARING);
		}
		entity.setState(dto.getState());
		return entity;
	}

	@Override
	public String toString() {
		return "PostingDTO [id=" + id + ", imgs=" + imgs + ", createTime=" + createTime + ", title=" + title
				+ ", authorName=" + authorName + ", content=" + content + ", type=" + type + "]";
	}

}
